package com.humanmonth.home.component.page.htree
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.controls.Alert;
	import mx.core.Application;
	import mx.events.FlexEvent;
	import mx.managers.PopUpManager;
	
	/**
	 * 创建连线的表单
	 * @author 林子龙
	 * 
	 */
	public class MyLineFormAs extends MyLineForm
	{
		public static var whiteBoard:WhiteBoardAs;
		
		private var line:MyLine;
		
		public function MyLineFormAs()
		{
			super();
			this.addEventListener(FlexEvent.CREATION_COMPLETE,myInit);
		}
		
		public function setLine(line:MyLine):void{
			this.line=line;
			this.startNode.selectedItem=line.startNode;
			this.endNode.selectedItem=line.endNode;
		}
		
		private function myInit(event:Event):void{
			this.myCancel.addEventListener(MouseEvent.CLICK,removeMe);
			this.myConfirm.addEventListener(MouseEvent.CLICK,addLine);
			this.initData();
			whiteBoard=Application.application.hTree.whiteBoard;
		}
		
		/**
		 *初始化数据 
		 */
		private function initData():void{
			this.startNode.dataProvider=NodeAs.allNode;
			this.startNode.labelField="myName";
			this.endNode.dataProvider=NodeAs.allNode;
			this.endNode.labelField="myName";
		}
		
		/**
		 *增加连线 
		 */
		private function addLine(event:Event):void{
			if(this.startNode.selectedItem==this.endNode.selectedItem){
				Alert.show("起始和结束节点不能为同一节点");
				return;
			}
			if(this.line==null){	
				var myLine:MyLine=new MyLine(NodeAs(startNode.selectedItem).myId,NodeAs(this.endNode.selectedItem).myId);
			}else{
				this.line.startNode=NodeAs(this.startNode.selectedItem);
				this.line.endNode=NodeAs(this.endNode.selectedItem);
			}
			MyLine.drawAll();
			this.removeMe();
		}
		
	}
}